package com.xhj.controller;

import com.xhj.entity.SubjectData;
import com.xhj.service.SubjectService;
import com.xhj.util.ResultEntity;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@Api(value="课程分类管理")
@RestController
@CrossOrigin
@RequestMapping("/EduAdmin/subject/")
@Slf4j
public class SubjectController {

    @Autowired
    private SubjectService subjectService;

    @ApiOperation(value = "Excel批量导入")
    @RequestMapping("addSubject")
    public ResultEntity addSubject(@RequestParam("file") MultipartFile file){
        subjectService.importSubjectData(file,subjectService);
        return ResultEntity.successWithData();
    }

    @ApiOperation(value = "获取课程分类数据并封装成实体类")
    @RequestMapping("list")
    public ResultEntity getSubjectData(){
        List<SubjectData> subjectData = subjectService.getSubjectListData();
        return ResultEntity.successWithData().data("subjectData",subjectData);
    }
}
